package com.itheima.controller.systemInfo;

import com.itheima.domin.pojo.Dept;
import com.itheima.domin.vo.Result;
import com.itheima.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 部门控制
 * @Author:上官徵羽
 * @Date: 2025/07/10 10:16
 * @Description TODO 今日内容:
 */
@RestController
@Slf4j
@RequestMapping(value = "/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;

    /**部门查询列表*/
    //@RequestMapping(method = RequestMethod.GET)
    @GetMapping
    public Result findAll(){
        log.info("DeptController findAll");
        //调用业务
        return Result.success(deptService.findAll());
    }

    /** 删除部门 */
    //@RequestMapping(method = RequestMethod.DELETE)
    @DeleteMapping
    public Result deleteDept(Integer id){
        log.debug("DeptController deleteDept{}",id);
        deptService.delete(id);
        return Result.success();
    }


    /** 添加部门*/
    //@RequestMapping(method = RequestMethod.POST)
    @PostMapping
    public Result add(@RequestBody Dept dept){
        log.info("DeptController add{}",dept);
        deptService.add(dept);
        return Result.success();
    }

    /** 指定查询 */
    //@RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @GetMapping(value = "/{id}")
    public Result findById(@PathVariable(name = "id") Integer id){
        log.debug("DeptController findById{}",id);
        return Result.success(deptService.selectId(id));
    }

    /** 修改部门 */
    //@RequestMapping(method = RequestMethod.PUT)
    @PutMapping
    public Result updateId(@RequestBody Dept dept){
        log.warn("DeptController updateId{}",dept);
        deptService.updateId(dept);
        return Result.success();
    }
}
